package com.lexc.watermq.broker;

import com.lexc.watermq.broker.cache.CommonCache;
import com.lexc.watermq.broker.config.GlobalPropertiesLoader;
import com.lexc.watermq.broker.config.TopicInfoLoader;
import com.lexc.watermq.broker.constants.BrokerConstants;
import com.lexc.watermq.broker.core.CommitLogAppendHandler;
import com.lexc.watermq.broker.model.WaterMQTopicModel;

import java.io.IOException;
import java.util.List;

/**
 * createTime：2025-08-16 14:46
 * description：broker启动
 */
public class BrokerStartUp {

    private GlobalPropertiesLoader globalPropertiesLoader;
    private TopicInfoLoader topicInfoLoader;

    private CommitLogAppendHandler commitLogAppendHandler;

    /**
     * 初始化配置
     */
    public void initProperties() throws IOException {
        globalPropertiesLoader = new GlobalPropertiesLoader();
        globalPropertiesLoader.loadProperties();

        topicInfoLoader = new TopicInfoLoader();
        topicInfoLoader.loadProperties();

        List<WaterMQTopicModel> topicModelList = CommonCache.getTopicModelList();
        //String waterMQHome = CommonCache.getGlobalProperties().getWaterMQHome();
        for (WaterMQTopicModel tmItem : topicModelList) {
            String topicName = tmItem.getTopic();
            //String filePath = waterMQHome + BrokerConstants.BASE_STORE_PATH.getVal() + topicName;
            commitLogAppendHandler.prepareMMapLoading(topicName);
        }
    }

    public static void main(String[] args) {
        //1.加载全局变量

        //2.模拟初始化文件映射

        //3.test
    }
}
